<template>
	<view class="content" v-show="load">
		<view v-if="addressList==null||addressList.length==0" class="con">
			<image src="../../static/bg/wei.png" style="width: 400upx;height: 400upx;"></image>
			<view class="text">您还没有收货地址哦</view>
			<view class="bt" @tap="add()">新建地址</view>
		</view>
		<view v-else>
			<scroll-view scroll-y class="scroll">
				<view class="item" v-for="(item,index) in addressList" :key="index" @tap="choiseAddress(item.id)">
					<view class="item_name">
						<view style="color: #333333;font-size: 32upx;">{{item.receiveName}}</view>
						<view style="color: #555555;">{{item.receivePhone}}</view>
					</view>
					<view style="color: #808080;margin-top: 10upx;">{{item.province+' '+item.city+' '+item.area+' '+item.receiveAddress}}</view>
					<view class="item_name" style="margin-top: 30upx;">
						<view v-if="item.defaultFlag==1" class="def">
							默认
						</view>
						<view v-if="item.defaultFlag!=1" style="width: 100upx;">
						</view>
						<view>
							<view>
								<view style="color: #555555;" @tap.stop="edit(item.id)">编辑</view>
								<uni-icon type="compose" color="#888888"></uni-icon>
							</view>
							<view style="margin-left: 30upx;" @tap.stop="del(item.id)">
								<view style="color: #555555;">删除</view>
								<uni-icon type="trash" color="#888888"></uni-icon>
							</view>
						</view>
					</view>

				</view>
			</scroll-view>

			<view class="buttom" @tap="add()">
				<view class="bt_add">
					添加地址
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		get_,
		getWithParam
	} from '../../common/request.js';
	import api from '../../common/api.js';
	import uniIcon from '../../components/uni-icon.vue';
	import {
		parseParam
	} from "../../common/util.js";
	export default {
		components: {
			uniIcon
		},
		data() {
			return {
				load:false,
				visiable: false,
				addressList: [],
				param: {}
			}
		},
		onLoad(option) {
			console.log("locad", option)
			this.param = option
		},
		onShow() {
			this.initData()
		},
		methods: {
			choiseAddress(id) {
				if (this.param == null || Object.keys(this.param).length === 0) {
					return
				}
				this.param['addressId'] = id
				uni.navigateTo({
					url: "../order/index?" + parseParam(this.param)
				})
			},
			edit(id) {
				uni.navigateTo({
					url: "./addAddress?id=" + id
				})
			},
			del(id) {
				uni.showModal({
					title: "",
					content: "确认删除地址?",
					success: (e) => {
						if (e.confirm) {
							getWithParam(api.ADDRESS_DELETE, {
								id
							}).then(res => {
								this.initData()
							})
						}
					}

				})
			},
			initData() {
				get_(api.ADDRESS_LIST).then(res => {
					this.addressList = res.data
					this.load=true
				})
			},
			add() {
				uni.navigateTo({
					url: './addAddress'
				})
			}
		}
	}
</script>

<style>
	.def {
		padding: 5upx 10upx;
		box-sizing: border-box;
		color: #FF1493;
		background-color: #FAEBD7;
		font-size: 24upx;
	}

	.item_name {
		justify-content: space-between;
		align-items: flex-end;
	}

	.item {
		background-color: #FFFFFF;
		padding: 20upx 40upx;
		box-sizing: border-box;
		flex-direction: column;
		border-bottom: 5px solid #F2F3F5;
	}

	.scroll {
		height: calc(100vh - 120upx);
	}

	.bt_add {
		width: 650upx;
		height: 80upx;
		color: #FFFFFF;
		background-color: #FE0036;
		border-radius: 10upx;
		align-items: center;
		justify-content: center;
		font-size: 32upx;
		font-weight: 600;
	}

	.buttom {
		position: fixed;
		width: 750upx;
		height: 120upx;
		justify-content: center;
		align-items: center;
		bottom: 0;
		left: 0;
		z-index: 100;
	}

	.con {
		background-color: #FFFFFF;
		height: 100vh;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.text {
		font-size: 32upx;
		color: #888888;
	}

	.bt {
		padding: 10upx 10upx;
		box-sizing: border-box;
		border: 1px solid #FE0036;
		color: #FE0036;
		border-radius: 10upx;
		margin-top: 40upx;
	}
</style>
